package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

// 归还图书
public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书");
        System.out.println("请输入你想借阅的书籍名称：");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getPos(i);
            if (name.equals(book.getName())){
                if(book.getBorrowed() ==  false){
                    System.out.println("你要归还的书籍，已归还。无法重复此操作。");
                    System.out.println("信息如下:");
                    System.out.println(book);
                    return;
                }
        // true 表示已借出，归还时，将 isBorrowed 置为false。表示归还成功
                book.setBorrowed(false);
                System.out.println("归还成功！");
                System.out.println(book);
                return;
            }
        }
        System.out.println("你要归还的书籍，不属于本图书馆。");
    }
}
